"""
generates the histogram (figure 1)
"""
import pandas as pd
import numpy as np
from statsmodels.iolib.foreign import genfromdta

from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.pyplot as plt

plt.rcParams['pdf.fonttype'] = 42
plt.rcParams['ps.fonttype'] = 42

def gen_histogram_ymax_bw(x,nbins,xlabel,ylabel,label_fontsize,xaxis_min,xaxis_max,yaxis_max,box_xcoord, box_ycoord,style, filename):
    """
    creaes a hisotgram w/ a box contianing mean, median, std dev
    """
    plt.style.use(style)

    fig, ax = plt.subplots(1)


    mu     = x.mean()
    median = np.median(x)
    sigma  = x.std()

    textstr = '$\mu=%.3f$\n$\mathrm{median}=%.3f$\n$\sigma=%.3f$'%(mu, median, sigma)

    ax.hist(x, nbins, normed=True,rwidth=0.95)

    # these are matplotlib.patch.Patch properties
    props = dict(boxstyle='round', facecolor='white', alpha=0.5)

    # place a text box in upper left in axes coords
    ax.text(box_xcoord, box_ycoord, textstr, transform=ax.transAxes, fontsize=14,
            verticalalignment='top', bbox=props)

    #ax.grid(True)
    ax.set_xlabel(xlabel,fontsize = label_fontsize)
    ax.set_ylabel(ylabel,fontsize = label_fontsize)

    ax.set_xlim(xaxis_min, xaxis_max)
    ax.set_ylim(0.0, yaxis_max)

    plt.savefig(filename + '.pdf',bbox_inches='tight',format='pdf')
    plt.close()
